<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>post_pic</title>
    <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>
    
    <style>
        .input1 {
            width: 80%;
            margin: 5px 5% 0 5%;
            height: 20px;
            background: #ebdad3;
            border: 1px solid #1B65C0;
            font: normal 15px/20px Microsoft Yahei;
        }
        .input2 {
            width: 80%;
            margin: 5px 5% 0 5%;
            height:100px;
            background: #ebdad3;
            border: 1px solid #1B65C0;
            font: normal 15px/20px Microsoft Yahei;          
        }
        button{
            background: none repeat scroll 0 0 #EEE;
            display: inline-block;
            font-weight: 800;
            margin: 1px 1px;
            padding: 0 2px;
            border-radius: 11px;
        }
        #submit
        {
            width: 80%;
            margin: 5px 5% 0 5%;
            background: #3A88E4;
            border: 1px solid #1B65C0;
            color: #FFF !important;
            font: normal 20px/30px Microsoft Yahei;
            line-height: 200%;
            text-align: center;
            border-radius: 10px;
        }
    </style>
</head>

<body> 
    <div>
        <form method="POST" action="/post_pic/">
            <div>
                <input class="input1" type="text" placeholder="a=2" name="a">
                <!-- type="button"这样才不提交 -->
                <!-- "f1()",而不是"f1" -->
                <!-- "f('a')"外面是双引号，那里面就是单引号 -->
                <button type="button" onclick="f('a')">删除</button>
            </div>
            <div>
                <input class="input1" type="text" placeholder="b=a+50" name="b">
                <button type="button" onclick="f('b')">删除</button>
            </div>
            <div>
                <textarea class="input2" name="pic_url_base" placeholder='
                {:02d}填充字符是0，宽度是d，默认右对齐>，十进制d'></textarea>
                <button type="button" onclick="f('pic_url_base')">删除</button>
                <button type="button" onclick="f2('pic_url_base')">变形</button>
            </div>
            <div>
                <button id='submit' type="submit">提交</button>
            </div>
        </form>
    </div>
</body>
<script>
    // 删除功能
    function f(obj) {
        // document.getElementsByName("a").values = "";     // 是传回来一个数组
        // document.getElementsByName("a")[0].values = "";  // 不是values，是value
        document.getElementsByName(obj)[0].value = "";
    }
    // 变形功能
    function f2(obj) {
        // document.getElementsByName("a").values = "";     // 是传回来一个数组
        // document.getElementsByName("a")[0].values = "";  // 不是values，是value
        var a = document.getElementsByName(obj)[0].value;
        var end = "";
        if(a.slice(-3)=="jpg")
        {
            end = "jpg"
        }
        else if(a.slice(-3)=="zip")
        {
            end = "zip"
        }
        else if(a.slice(-3)=="png")
        {
            end = "png"
        }
        document.getElementsByName(obj)[0].value = a.slice(0,-4) + "{}." + end;
    }
</script>

</html>